<template>
  <div>
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="表单名称" prop="formName">
        <el-input
          v-model="queryParams.formName"
          placeholder="请输入表单名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['demo:form:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['demo:form:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['demo:form:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['demo:form:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="data" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="ID" align="center" prop="id" />
      <el-table-column label="表单名称" align="center" prop="formName" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['demo:form:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdateJson(scope.row)"
            v-hasPermi="['demo:form:edit']"
          >设计</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleShowJson(scope.row)"
            v-hasPermi="['demo:form:edit']"
          >预览</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['demo:form:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import ListMixin from "@/minixs/basic/list"
import request from "@/utils/request";
export default {
  name: "list",
  mixins:[ListMixin],
  data() {
    return {
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        formName: null,
      },
      // 删除地址
      deletedUrl:"/demo/form/",
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询动态表单列表 */
    getList() {
      this.loading = true;
      request({
        url: '/demo/form/list',
        method: 'get',
        params: this.queryParams
      }).then(response => {
        this.data = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },

    /** 导出按钮操作 */
    handleExport() {
      this.download('/demo/form/export', {
        ...this.queryParams
      }, `form_${new Date().getTime()}.xlsx`)
    },

    /**
     * 设计json
     */
    handleUpdateJson(row){
      const id = row.id
      this.$emit("update-handle", {
        id:id,
        open: true,
        title: "设计表单",
        type:'UPDATE_JSON'
      })
    },
    /**
     * 预览json
     */
    handleShowJson(row){
      console.log(row)
      const id = row.id
      this.$emit("detail-handle", {
        id:id,
        open: true,
        title: "预览表单",
        type:'SHOW_JSON'
      })
    },
  }
};
</script>
